package controleur;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import model.GestionAddress;
import view.SearchForm;

public class ActionSearch implements ActionListener{

	
	private SearchForm search;
	public static ArrayList<String> cont1;
	public static JScrollPane sp;
    public static DefaultTableModel table;
    public static boolean checked = false;
    
    /**
	 * @return the table
	 */
	public DefaultTableModel getTable() {
		return table;
	}

	/**
	 * @param table the table to set
	 */
	public void setTable(DefaultTableModel table) {
		this.table = table;
	}

	private final String cols[] = {"First Name", "Last Name","Group", "Address Home", "Address Company", "Home Phone",
    		"Mobile Phone", "Professional Phone", "Personal Email", "Professional Email", "Web Page", "Picture"};
	
	public ActionSearch(SearchForm search){
		this.search=search;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
		if (e.getSource() == search.getJButtonValidate()) {
			
			GestionAddress gA = new GestionAddress();
            cont1 = gA.searchContact(MainControleur.data, search.getJTextFieldFname().getText(), search.getJTextFieldLname().getText(),
            		search.getJTextFieldEmailPers().getText());
            
            ArrayList<ArrayList<String>> dd = new ArrayList<ArrayList<String>>();
            dd.add(cont1);
            MainControleur.fen.contactInfo(dd);
            
            if (cont1 != null){
	            if (checked) MainControleur.fen.getJframe1().remove(sp);
	            if (ActionVue.checked) MainControleur.fen.getJframe1().remove(ActionVue.sp);

			    checked = true;
            }
            
            SearchForm.jframe1.setVisible(false);

        }
		
	}
}
